// 添加目录弹框组件 // ref="directorysFormRef"
<template>
  <div class="container">
    <el-form :model="directorysForm" :rules="directoryRules" label-width="80px" class="demo-ruleForm">
      <el-form-item class="elform" label="所属学科" prop="subjectID" v-if="!queryVal.id">
        <el-select v-model="directorysForm.subjectID" placeholder="请选择" style="width: 100%;">
          <el-option :label="item.label" :value="item.value" v-for="item in selectValue" :key="item.value"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item class="elform" label="目录名称" prop="directoryName">
        <el-input v-model="directorysForm.directoryName" placeholder="请输入目录名称" style="width: 100%;"></el-input>
      </el-form-item>
    </el-form>

    <!-- 底部两个按钮 -->
    <div slot="footer" style="text-align:right" class="dialog-footer">
      <el-button @click="$emit('close')">取 消</el-button>
      <el-button type="primary" @click="addDirForm">确 定</el-button>
    </div>
  </div>
</template>

<script>
//添加目录
import { add } from '../../api/hmmm/directorys'

export default {
  name: 'directorysAdd',
  data() {
    return {
      // 添加目录的数据
      directorysForm: {
        directoryName: '', //目录名称
        // 下拉框的值
        subjectID: ''
      },
      //校验规则
      directoryRules: {
        directoryName: { required: true, message: '请输入目录名称', trigger: 'blur' },
        subjectID: { required: true, message: '请输入ID', trigger: 'blur' }
      }
    }
  },
  props: {
    selectValue: {
      type: Array,
      required: true
    },
    //存放查询参数
    queryVal: {
      type: Object,
      require: true
    }
  },
  methods: {
    // 点击新增目录
    async addDirForm() {
      if (this.queryVal.id) {
        this.directorysForm.subjectID = parseInt(this.queryVal.id)
      }
      try {
        await add(this.directorysForm)
        this.$message.success('添加目录成功')
        this.$emit('close')
        this.$emit('updatetable')
      } catch (error) {
        console.log(error)
        this.$message.error('添加目录失败')
      }
    }
  }
}
</script>

<style scoped lang="less"></style>
